home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d7 / commdrvr.arc / RS232.ASM < prev    next >
Assembly Source File  |  1988-04-11  |  10KB  |  489 lines

  1.     page    60,132
  2. ;***********************************************************
  3. ;**    Configuration Program for Communications           **
  4. ;**    Copyright (C) Texas Instruments, Inc. 1986         **
  5. ;**                                                       **
  6. ;**    Author: Greg Haley                                 **
  7. ;**    Project Start: 09/15/86                            **
  8. ;**    Last Revision: 11/18/86                            **
  9. ;***********************************************************
  10.  
  11.     name    RS232
  12.     title    Config Program for Serial Communications
  13. cr    equ    0dH
  14. lf    equ    0aH
  15.  
  16. code    segment
  17.     assume    cs:code, ds:code, es:code, ss:code
  18.     org    80h
  19. char_count label byte
  20.     org    81h
  21. command_line label byte
  22.     org    100h
  23. RS232     proc    near
  24.     jmp     start
  25.  
  26. ; variables 
  27. device    db    'AUX',0            ; Device name
  28. handle    dw    0            ; Handle for AUX
  29. DCW    dw    1000000001000000b    ; Device configuration word
  30. DCB    db    10100001b        ; Key_in, Echo_out, DTR
  31. c_line    db    256 dup (?)        ; Copy of command line
  32. count    dw    0            ; Num. of chars in command line
  33.     dw    40 dup (?)        ; New stack
  34. top_stack label word
  35.  
  36. msg:
  37.     db    cr,lf,'RS232 Configuration Copyright (C) '
  38.     db    'Texas Instruments 1986'
  39.     db    cr,lf,'Author: Greg Haley',cr,lf
  40.     db    cr,lf,'Current serial configuration:'
  41.        db    cr,lf,'Port='
  42. port_n    db    ' , Speed='
  43. speed    db    '    , Parity='
  44. parity    db    '    , Data bits='
  45. data    db    ' , Stop bits='
  46. stop    db    ' , Busy='
  47. busy    db    '        ',cr,lf,'$'
  48.  
  49. busy_tbl dw    no_busy    
  50.     dw    scf_busy
  51.     dw    dsr_busy
  52.     dw    xon_busy
  53.  
  54. no_busy    db    'NONE    '
  55. scf_busy db    'SCF     '
  56. dsr_busy db    'DSR     '
  57. xon_busy db    'XON-XOFF'
  58.  
  59. p_tbl    dw    par_none
  60.     dw    par_odd
  61.     dw    par_none
  62.     dw    par_even
  63.  
  64. par_none db    'NONE'
  65. par_odd    db    ' ODD'
  66. par_even db    'EVEN'
  67.  
  68. s_tbl    dw    s_110
  69.     dw    s_150
  70.     dw    s_300
  71.     dw    s_600
  72.     dw    s_1200
  73.     dw    s_2400
  74.     dw    s_4800
  75.     dw    s_9600
  76.  
  77. s_110    db    ' 110'
  78. s_150    db    ' 150'
  79. s_300    db    ' 300'
  80. s_600    db    ' 600'
  81. s_1200    db    '1200'
  82. s_2400    db    '2400'
  83. s_4800    db    '4800'
  84. s_9600    db    '9600'
  85.  
  86. ; Program starts here
  87. start:    
  88. ; set up new stack
  89.     mov    sp,offset top_stack
  90.     mov    ax,cs
  91.     mov    ds,ax
  92.     mov     es,ax
  93.  
  94. ; open handle
  95.     mov    dx,offset device
  96.     mov    ax,3d02h
  97.     int    21h
  98.     jnc    open_1
  99.     jmp    error
  100. open_1:
  101.     mov    handle,ax
  102.     mov    bx,ax
  103.  
  104. ; get command line length
  105.     mov    al,char_count
  106.     or    al,al
  107.     jnz    command_1
  108.     jmp    display_dcw
  109. command_1:
  110.     cbw
  111.     mov    count,ax
  112.  
  113. ; get command line
  114.     mov    cx,ax
  115.     mov    si,offset command_line
  116.     mov    di,offset c_line
  117. copy_string:
  118.     lodsb
  119.     cmp    al,'a'            ; Is it lower case?
  120.     jb    upper_case        ;  No, skip
  121.     and    al,11011111b        ;  Yes, convert to upper case
  122. upper_case:
  123.     stosb                ; Store upper case value
  124.     loop    copy_string        ; Loop 'til done
  125.     
  126. ; get DCW
  127.     call    get_dcw
  128.     jnc    get_dcw_1
  129.     jmp    error
  130. get_dcw_1:
  131.  
  132. ; look for word "port" ("po")
  133.     mov    di,offset c_line
  134.     mov    cx,count
  135. look4port:
  136.     mov    al,'P'
  137.     repnz    scasb            ; find string
  138.     jcxz    port_done
  139.     mov    si,di
  140.     lodsb                ; next char "O" ?
  141.     cmp    al,'O'
  142.     jne    look4port         ; No, look again
  143.     mov    al,'='            ; Now look for "=" char
  144.     repnz    scasb
  145.     jcxz    port_done
  146.  
  147.     mov    dl,'1'            ; find port number
  148.     mov    dh,'4'
  149.     mov    si,di
  150. get_port:
  151.     lodsb
  152.     cmp    al,dl            ; port 1 <= port <= 4 ?
  153.     jb     loop_port
  154.     cmp    al,dh
  155.     jg    loop_port
  156.     dec    al                  ; convert port to binary
  157.     and    al,00000011b
  158.     jmp    port_dcw        ; go change it
  159. loop_port:
  160.     loop    get_port
  161.  
  162.  
  163. ; modify DCW
  164. port_dcw:
  165.     and    dcw,1110011111111111b    ; reset port bits
  166.     mov    cl,11
  167.     xor    ah,ah
  168.     shl    ax,cl
  169.     or    dcw,ax
  170. port_done:    
  171.  
  172. ; look for word "data" ("da")
  173.     mov    di,offset c_line
  174.     mov    cx,count
  175.     mov    al,'D'
  176.     repnz    scasb            ; find string
  177.     jcxz    data_done
  178.     mov    si,di
  179.     lodsb                ; next char "A" ?
  180.     cmp    al,'A'
  181.     je    found_data        ; Yes, continue
  182.     jmp    data_done        ; No, exit
  183. found_data:
  184.     mov    al,'='            ; Now look for "=" char
  185.     repnz    scasb
  186.     jcxz    data_done
  187.  
  188.     mov    si,di
  189.     lodsb
  190.     cmp    al,'7'            ; 7 data bits?
  191.     jne    check_for_8
  192.     and    dcw,1011111111111111b    ; Store in proper bit
  193.     jmp    data_done        ; we're done
  194. check_for_8:
  195.     cmp    al,'8'                  ; 8 data bits
  196.     jne    data_done        ; 
  197.     or     dcw,0100000000000000b    ; Store in proper bit
  198. data_done:    
  199.  
  200. ; look for word "busy" ("bu")
  201.     mov    di,offset c_line
  202.     mov    cx,count
  203.     mov    al,'B'
  204.     repnz    scasb            ; find string
  205.     jcxz    busy_done
  206.     mov    si,di
  207.     lodsb                ; next char "U" ?
  208.     cmp    al,'U'
  209.     je    found_busy        ; Yes, continue
  210.     jmp    busy_done        ; No, exit
  211. found_busy:
  212.     mov    al,'='            ; Now look for "=" char
  213.     repnz    scasb
  214.     jcxz    busy_done
  215.  
  216.     mov    si,di
  217.     lodsb
  218.     cmp    al,'N'            ; No busy handling?
  219.     jne    busy_scf
  220.     and    dcw,1111110011111111b    ; Store in proper bits
  221.     jmp    busy_done        ; we're done
  222. busy_scf:
  223.     cmp    al,'S'            ; SCF busy handling?
  224.     jne    busy_dsr
  225.     and    dcw,1111110011111111b    ; Store in proper bits
  226.     or     dcw,0000000100000000b    ; Store in proper bits
  227.     jmp    busy_done        ; we're done
  228. busy_dsr:
  229.     cmp    al,'D'            ; No busy handling?
  230.     jne    busy_xon
  231.     and    dcw,1111110011111111b    ; Store in proper bits
  232.     or     dcw,0000001000000000b    ; Store in proper bits
  233.     jmp    busy_done        ; we're done
  234. busy_xon:
  235.     cmp    al,'X'            ; No busy handling?
  236.     jne    busy_done
  237.     or     dcw,0000001100000000b    ; Store in proper bits
  238. busy_done:    
  239.  
  240. ; look for word "speed" ("sp")
  241.     mov    di,offset c_line
  242.     mov    cx,count
  243. find_speed:
  244.     mov    al,'S'
  245.     repnz    scasb            ; find string
  246.     or     cx,cx
  247.     jnz    speed_A
  248.     jmp    speed_done
  249. speed_A:
  250.     mov    si,di
  251.     lodsb                ; next char "P" ?
  252.     cmp    al,'P'
  253.     jne    find_speed        ; No, look again
  254.     mov    al,'='            ; Now look for "=" char
  255.     repnz    scasb
  256.     or     cx,cx
  257.     jnz    speed_B
  258.     jmp    speed_done
  259. speed_B:
  260.  
  261.     mov    si,di
  262.     lodsb
  263.     cmp    al,'1'            ; 1 speed bit?
  264.     jne    speed_2
  265.     lodsb
  266.     cmp    al,'1'            ; 110 baud?
  267.     jne    speed_150
  268.     and    dcw,1111111110001111b    ; Store in proper bits
  269.     jmp    speed_done        ; we're done
  270. speed_150:
  271.     cmp    al,'5'            ; 150 baud?
  272.     jne    speed_1200
  273.     and    dcw,1111111110001111b    ; Store in proper bits
  274.     or     dcw,0000000000010000b    ; Store in proper bits
  275.     jmp    speed_done        ; we're done
  276. speed_1200:
  277.     cmp    al,'2'                  ; 1200 baud?
  278.     jne    speed_done
  279.     and    dcw,1111111110001111b    ; Store in proper bits
  280.     or     dcw,0000000001000000b    ; Store in proper bits
  281.     jmp    speed_done        ; we're done
  282. speed_2:
  283.     cmp    al,'2'                  ; 2400 baud?
  284.     jne    speed_3
  285.     and    dcw,1111111110001111b    ; Store in proper bits
  286.     or     dcw,0000000001010000b    ; Store in proper bits
  287.     jmp    speed_done        ; we're done
  288. speed_3:
  289.     cmp    al,'3'                  ; 300 baud?
  290.     jne    speed_4
  291.     and    dcw,1111111110001111b    ; Store in proper bits
  292.     or     dcw,0000000000100000b    ; Store in proper bits
  293.     jmp    speed_done        ; we're done
  294. speed_4:
  295.     cmp    al,'4'                  ; 4800 baud?
  296.     jne    speed_6
  297.     and    dcw,1111111110001111b    ; Store in proper bits
  298.     or     dcw,0000000001100000b    ; Store in proper bits
  299.     jmp    speed_done        ; we're done
  300. speed_6:
  301.     cmp    al,'6'                  ; 600 baud?
  302.     jne    speed_9
  303.     and    dcw,1111111110001111b    ; Store in proper bits
  304.     or     dcw,0000000000110000b    ; Store in proper bits
  305.     jmp    speed_done        ; we're done
  306. speed_9:
  307.     cmp    al,'9'                  ; 9600 baud?
  308.     jne    speed_done
  309.     and    dcw,1111111110001111b    ; Store in proper bits
  310.     or     dcw,0000000001110000b    ; Store in proper bits
  311. speed_done:    
  312.  
  313. ; look for word "stop" ("st")
  314.     mov    di,offset c_line
  315.     mov    cx,count
  316. find_stop:
  317.     mov    al,'S'
  318.     repnz    scasb            ; find string
  319.     jcxz    stop_done
  320.     mov    si,di
  321.     lodsb                ; next char "T" ?
  322.     cmp    al,'T'
  323.     jne    find_stop        ; No, look again
  324.     mov    al,'='            ; Now look for "=" char
  325.     repnz    scasb
  326.     jcxz    stop_done
  327.  
  328.     mov    si,di
  329.     lodsb
  330.     cmp    al,'1'            ; 1 stop bit?
  331.     jne    stop_2
  332.     and    dcw,1111111111110111b    ; Store in proper bit
  333.     jmp    stop_done        ; we're done
  334. stop_2:
  335.     cmp    al,'2'                  ; 2 stop bits
  336.     jne    stop_done        ; 
  337.     or     dcw,0000000000001000b    ; Store in proper bit
  338. stop_done:    
  339.  
  340. ; look for word "parity" ("pa")
  341.     mov    di,offset c_line
  342.     mov    cx,count
  343. find_parity:
  344.     mov    al,'P'
  345.     repnz    scasb            ; find string
  346.     jcxz    parity_done
  347.     mov    si,di
  348.     lodsb                ; next char "A" ?
  349.     cmp    al,'A'
  350.     jne    find_parity        ; No, look again
  351.     mov    al,'='            ; Now look for "=" char
  352.     repnz    scasb
  353.     jcxz    parity_done
  354.  
  355.     mov    si,di
  356.     lodsb
  357.     cmp    al,'N'            ; No parity?
  358.     jne    parity_odd
  359.     and    dcw,1111111111111100b    ; Store in proper bits
  360.     jmp    parity_done        ; we're done
  361. parity_odd:
  362.     cmp    al,'O'            ; ODD parity?
  363.     jne    parity_even
  364.     and    dcw,1111111111111100b    ; Store in proper bits
  365.     or     dcw,0000000000000001b    ; Store in proper bits
  366.     jmp    parity_done        ; we're done
  367. parity_even:
  368.     cmp    al,'E'            ; EVEN parity?
  369.     jne    parity_done
  370.     or     dcw,0000000000000011b    ; Store in proper bits
  371. parity_done:    
  372.  
  373. ; Turn on Serial bit in DCW
  374.     or     dcw,1000000000000000b
  375.  
  376. ; Set Driver Options to Key_in ON, Echo_out ON, and DCW mode
  377.      mov    dx,offset DCB
  378.      mov    bx,handle
  379.      mov    cx,1
  380.      mov    ax,4403h
  381.      int    21h
  382.  
  383. ; Set new DCW
  384.     mov    dx,offset DCW
  385.     mov    bx,handle
  386.     mov    cx,2
  387.     mov    ax,4403h
  388.     int    21h
  389.  
  390. ; display current DCW
  391. display_dcw:
  392.     call    get_dcw
  393.     call    print_dcw
  394.  
  395. ; terminate program
  396. exit: 
  397.     mov    al,0
  398.     jmp     short terminate
  399. error:
  400.     mov    al,1
  401. terminate:
  402.     mov    ah,4ch
  403.     int    21h
  404.  
  405. ; Get Device Config Word
  406. get_dcw    proc    near
  407.     mov    dx,offset DCW
  408.     mov    bx,handle
  409.     mov    cx,2
  410.     mov    ax,4402h
  411.     int    21h
  412.     ret
  413. get_dcw    endp
  414.  
  415. print_dcw proc     near
  416. ; insert port number
  417.     mov    dx,dcw
  418.     mov    cl,11
  419.     shr    dx,cl
  420.     and    dl,00000011b
  421.     or    dl,00110000b
  422.     inc    dl
  423.     mov    port_n,dl
  424.  
  425. ; insert speed
  426.     mov    dx,dcw
  427.     and    dx,0000000001110000b
  428.     mov    cl,3
  429.     shr    dl,cl
  430.     mov    bx,offset s_tbl
  431.     add    bx,dx
  432.     mov    si,[bx]
  433.     mov    di,offset speed
  434.     mov    cx,4
  435.     repz    movsb
  436.  
  437. ; insert parity
  438.     mov    dx,dcw
  439.     and    dx,0000000000000011b
  440.     shl    dx,1
  441.     mov    bx,offset p_tbl
  442.     add    bx,dx
  443.     mov    si,[bx]
  444.     mov    di,offset parity
  445.     mov    cx,4
  446.     repz    movsb
  447.  
  448. ; insert data bits
  449.     mov    dx,dcw
  450.     mov    al,'7'
  451.     and    dx,0100000000000000b
  452.     jz    data_7
  453.     inc    al
  454. data_7:
  455.     mov    data,al
  456.  
  457. ; insert stop bits
  458.     mov    dx,dcw
  459.     mov    al,'1'
  460.     and    dx,0000000000001000b
  461.     jz    stopis2
  462.     inc    al
  463. stopis2:
  464.     mov    stop,al
  465.  
  466. ; insert busy
  467.     mov    dx,dcw
  468.     and    dx,0000001100000000b
  469.     xchg    dl,dh
  470.     shl    dx,1
  471.     mov    bx,offset busy_tbl
  472.     add    bx,dx
  473.     mov    si,[bx]
  474.     mov    di,offset busy
  475.     mov    cx,8
  476.     repz    movsb
  477.  
  478. ; print message
  479.     mov    dx,offset msg
  480.     mov    ah,9
  481.     int    21h
  482.  
  483.     ret
  484. print_dcw endp
  485.  
  486. RS232     endp
  487. code    ends
  488.     end    RS232 
  489.